<!DOCTYPE html>
<html>

<head>
    <#include "/yq/admin/components/meta.html" />
    <title>蓁奕科技 ${metaTitleSuffix!}</title>
    <#include "/yq/admin/components/stylesheets.html" />
    <style>
        .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    .el-tag+.el-tag {
        margin-left: 10px;
    }

    .button-new-tag {
        margin-left: 10px;
        height: 32px;
        line-height: 30px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .input-new-tag {
        width: 90px;
        margin-left: 10px;
        vertical-align: bottom;
    }

    .field-options {
        margin-top: 10px;
        padding: 5px 10px;
        border-radius: 4px;
        border: 1px solid #dcdfe6;
    }
    .showmodel{
        height: 500px;

    }
    .latlng{
        margin-top: 2
        0px;
    }
    </style>
</head>

<body>
    <div id='app'>
        <el-container>
            <#assign menuIndex="1-2" />
            <#include "/yq/admin/components/menu.html" />
            <el-container>
                <#include "/yq/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-form ref="form" :model="form" label-width="120px">
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="商铺">
                                        <el-select v-model="form.shopId" placeholder="请选择" :disabled='form.shopId!=null || ${userRole!2} === 2'>
                                            <el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="标题">
                                        <el-input v-model="form.title"></el-input>
                                        <span style="color: #888;">限制字数8个</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="副标题">
                                        <el-input v-model="form.subtitle" type='text'></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="星级">
                                        <!-- <el-input v-model="form.star" type='number' disabled></el-input> -->
                                        <el-select v-model="form.star">
                                            <el-option :value="0"></el-option>
                                            <el-option :value="1"></el-option>
                                            <el-option :value="2"></el-option>
                                            <el-option :value="3"></el-option>
                                            <el-option :value="4"></el-option>
                                            <el-option :value="5"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="热门推荐">
                                        <el-checkbox v-model="form.isHot" :false-label='0' :true-label='1' :checked='form.isHot == 1' border>热门推荐</el-checkbox>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="隐藏">
                                        <el-checkbox v-model="form.isHidden" :false-label='0' :true-label='1' :checked='form.isHidden == 1' border>隐藏</el-checkbox>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="价格">
                                        <el-input v-model="form.price" type='number'></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="原价">
                                        <el-input v-model="form.salePrice" type='number'></el-input>
                                    </el-form-item>
                                </el-col>
                                <#if hasPermission('PROD_IS_NEW')>
                                    <el-col :span="8">
                                        <el-form-item label="新品上架">
                                            <el-checkbox v-model="form.isNew" :false-label='0' :true-label='1' :checked='form.isNew == 1' border ${hasEditPermission('PROD_IS_NEW')}>新品上架</el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                            </el-row>
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="商店类目">
                                        <!-- <el-input v-model="form.type"></el-input> -->
                                        <el-select v-model="form.categoryId">
                                            <el-option :value="item.id" :label="item.title" v-for="(item, index) in categories" :disabled="item.status == 0"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="物流">
                                        <el-checkbox v-model="form.isNeedTrack" :false-label='0' :true-label='1' :checked='form.isNeedTrack == 1' border>需要物流</el-checkbox>
                                    </el-form-item>
                                </el-col>
                                <#if hasPermission('PROD_COUPON')>
                                    <el-col :span="8">
                                        <el-form-item label="优惠券">
                                            <el-checkbox v-model="form.isCoupon" :false-label='0' :true-label='1' :checked='form.isCoupon == 1' border ${hasEditPermission('PROD_COUPON')}>优惠券</el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                            </el-row>
                            <#if hasPermission('PROD_GROUP')>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="团购">
                                            <el-checkbox v-model="form.isGroup" :false-label='0' :true-label='1' :checked='form.isGroup == 1' border ${hasEditPermission('PROD_GROUP')}>团购</el-checkbox>
                                        </el-form-item>
                                    </el-col>
                                    <#if hasPermission('PROD_GROUP_COUNT')>
                                        <el-col :span="8">
                                            <el-form-item label="开团人数(人)">
                                                <el-input v-model="form.groupCount" type='number' :disabled='form.isGroup!=1' ${hasEditPermission('PROD_GROUP_COUNT')}></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </#if>
                                    <#if hasPermission('PROD_GROUP_HOURS')>
                                        <el-col :span="8">
                                            <el-form-item label="拼团时限(小时)">
                                                <el-input v-model="form.groupHours" type='number' :disabled='form.isGroup!=1' ${hasEditPermission('PROD_GROUP_HOURS')}></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </#if>
                                    <#if hasPermission('PROD_GROUP_END')>
                                        <el-col :span="8">
                                            <el-form-item label="拼团结束时间">
                                                <el-date-picker v-model="form.endTime" type="datetime" placeholder="选择结束时间" value-format="yyyy-MM-dd HH:mm:ss">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </#if>
                                </el-row>
                            </#if>
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="库存">
                                        <el-input v-model="form.storage" type='number'></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="优先级">
                                        <el-input v-model="form.sort" type='number'></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <#if hasPermission('PROD_CARDTYPE')>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="卡券类型">
                                            <el-select v-model="form.cardType" :disabled="form.id" ${hasEditPermission('PROD_CARDTYPE')}>
                                                <el-option :value="0" label="非卡券"></el-option>
                                                <el-option :value="1" label="次卡"></el-option>
                                                <el-option :value="2" label="日卡"></el-option>
                                                <el-option :value="3" label="过期卡"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="form.cardType == 1">
                                        <el-form-item label="使用次数">
                                            <el-input v-model="form.cardUseLimit" type='number' ${hasEditPermission('PROD_CARDTYPE')}></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="form.cardType == 2">
                                        <el-form-item label="有效天数">
                                            <el-input v-model="form.cardAvailableDay" type='number' ${hasEditPermission('PROD_CARDTYPE')}></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="form.cardType == 3">
                                        <el-form-item label="过期时间">
                                            <el-date-picker v-model="form.cardExpire" type="date" placeholder="过期时间" value-format="yyyy-MM-dd 23:59:59" ${hasEditPermission('PROD_CARDTYPE')}></el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </#if>
                            <el-row :gutter="20">
                                <el-col :span="24">
                                    <el-form-item label="简介">
                                        <el-input v-model="form.intro" type="textarea" rows='5'></el-input>
                                    </el-form-item>
                                </el-col>
                                <!-- <el-col :span="24">
                                    <el-form-item label="详情">
                                        <el-input v-model="form.content" type="textarea" rows='5'></el-input>
                                    </el-form-item>
                                </el-col> -->
                            </el-row>
                            <#if hasPermission('PROD_FORMAT')>
                                <el-row>
                                    <el-form-item label="规格">
                                        <el-button size="mini" @click="showSizeDialog()" ${hasEditPermission('PROD_FORMAT')}>添加规格</el-button>
                                        <el-table :data="sizes" style="width: 100%;">
                                            <el-table-column prop="title" label="规格">
                                            </el-table-column>
                                            <el-table-column prop="fee" label="价格">
                                            </el-table-column>
                                            <el-table-column prop="storage" label="库存">
                                            </el-table-column>
                                            <el-table-column prop="isHidden" label="隐藏">
                                                <template slot-scope="scope">
                                                    <span v-if="scope.row.isHidden == 1">是</span>
                                                    <span v-if="scope.row.isHidden == 0">否</span>
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="操作">
                                                <template slot-scope="scope">
                                                    <el-button type="text" @click="showSizeDialog(scope.row)" ${hasEditPermission('PROD_FORMAT')}>编辑</el-button>
                                                    <el-button type="text" @click="delSize(scope.row)" ${hasEditPermission('PROD_FORMAT')}>删除</el-button>
                                                    <el-button type="text" @click="moveSizeUp(scope.row)" ${hasEditPermission('PROD_FORMAT')}>上移</el-button>
                                                    <el-button type="text" @click="moveSizeDown(scope.row)" ${hasEditPermission('PROD_FORMAT')}>下移</el-button>
                                                </template>
                                            </el-table-column>
                                        </el-table>
                                    </el-form-item>
                                </el-row>
                            </#if>
                            <#if hasPermission('PROD_SERVICE')>
                                <el-row>
                                    <el-form-item label="服务标签">
                                        <el-tag :key="tag" v-for="tag in dynamicTags" closable :disable-transitions="false" @close="handleClose(tag)">
                                            {{tag}}
                                        </el-tag>
                                        <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
                                        </el-input>
                                        <el-button v-else class="button-new-tag" size="small" @click="showInput" ${hasEditPermission('PROD_SERVICE')}>+ 新增标签</el-button>
                                    </el-form-item>
                                </el-row>
                            </#if>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="封面">
                                        <el-upload class="avatar-uploader" :on-success="handleAvatarSuccess" :on-error="handleAvatarError" :http-request='uploadQnFile' list-type='picture' :show-file-list="false">
                                            <img v-if="form.cover" :src="form.cover" class="avatar">
                                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                        </el-upload>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="24">
                                    <el-form-item label="轮播图">
                                        <el-upload class="upload-demo" :http-request='uploadQnFile' :on-success='successImg' :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" list-type="picture-card">
                                            <el-button size="small" type="primary">选择文件</el-button>
                                        </el-upload>
                                    </el-form-item>
                                </el-col>
                                <#if hasPermission('PROD_GALLERY')>
                                    <el-col :span="24">
                                        <el-form-item label="商品长图">
                                            <el-upload class="upload-demo" :http-request='uploadQnFile' :on-success='handelGalleryImgSuccess' :on-preview="handlePreview" :on-remove="handleGalleryImgRemove" :file-list="gallery" list-type="picture-card">
                                                <el-button size="small" type="primary" ${hasEditPermission('PROD_GALLERY')}>选择文件</el-button>
                                            </el-upload>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <#if hasPermission('PROD_LOCATION')>
                                    <el-col :span="24">
                                        <el-form-item label="地图">
                                            <el-input type="textarea" v-model="form.address" ${hasEditPermission('PROD_LOCATION')}></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-dialog title="选取地址" :visible.sync="dialogTableVisible">
                                        <iframe id="mapPage" class="showmodel" width="100%" height="100%" frameborder=0 src="https://3gimg.qq.com/lightmap/components/locationPicker2/index.html?search=1&type=1&key=IHABZ-7MPCJ-TMOFI-KVGYP-DCKJV-GGBGM&referer=myapp&coord={{latlng}}">
                                        </iframe>
                                    </el-dialog>
                                    <el-col :span="24">
                                        <el-form-item>
                                            <el-button class="select" @click="dialogTableVisible = true" ${hasEditPermission('PROD_LOCATION')}>选取</el-button>
                                            <label v-if="form.latlng">({{form.latlng}})</label>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <el-col :span="24">
                                    <el-form-item label="分享标题">
                                        <el-input v-model="form.shareTitle"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="24">
                                    <el-form-item label="分享图片">
                                        <el-upload class="avatar-uploader" :on-success="handleShareImgSuccess" :on-error="handleShareImgError" :http-request='uploadQnFile' list-type='picture' :show-file-list="false">
                                            <img v-if="form.shareImage" :src="form.shareImage" class="avatar">
                                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                        </el-upload>
                                        <el-button type="text" @click="useCoverForShare" :disabled="!form.cover">使用封面图片</el-button>
                                    </el-form-item>
                                </el-col>
                                <#if hasPermission('PROD_MORE_INFO')>
                                    <el-col :span="24">
                                        <el-form-item label="额外信息">
                                            <el-select v-model="form.isNeedMoreInfo" ${hasEditPermission('PROD_MORE_INFO')}>
                                                <el-option :value="0" label="无"></el-option>
                                                <el-option :value="1" label="物流信息"></el-option>
                                                <el-option :value="2" label="报名信息（弃用）"></el-option>
                                                <el-option :value="3" label="个人信息"></el-option>
                                                <el-option :value="4" label="自定义信息"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <#if hasPermission('PROD_EXTRA')>
                                    <el-col :span="24">
                                        <el-form-item label="自定义字段">
                                            <el-table :data="extraFields" style="width: 100%; margin-bottom: 10px;">
                                                <el-table-column prop="title" label="名称" width="120">
                                                </el-table-column>
                                                <el-table-column prop="type" label="类型" width="70">
                                                    <template slot-scope="scope">
                                                        <span v-if="scope.row.type === 0">单选</span>
                                                        <span v-if="scope.row.type === 1">多选</span>
                                                        <span v-if="scope.row.type === 2">文本</span>
                                                        <span v-if="scope.row.type === 3">日期</span>
                                                        <span v-if="scope.row.type === 4">数字</span>
                                                        <span v-if="scope.row.type === 5">分割线</span>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column prop="options" label="选项">
                                                </el-table-column>
                                                <el-table-column label="操作" width="80">
                                                    <template slot-scope="scope">
                                                        <el-button type="text" @click="delField(scope.row)" ${hasEditPermission('PROD_EXTRA')}>删除</el-button>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                            <el-input v-model="fieldTitle" placeholder="字段名称" style="width: 220px;"></el-input>
                                            <el-select v-model="fieldType" placeholder="字段类型">
                                                <el-option :value="0" label="单选"></el-option>
                                                <el-option :value="1" label="多选"></el-option>
                                                <el-option :value="2" label="文本"></el-option>
                                                <el-option :value="3" label="日期"></el-option>
                                                <el-option :value="4" label="数字"></el-option>
                                                <el-option :value="5" label="分割线"></el-option>
                                            </el-select>
                                            <div class="field-options" v-if="fieldType === 0 || fieldType === 1">
                                                <el-tag :key="tag" v-for="tag in fieldOptions" closable :disable-transitions="false" @close="handleOptionClose(tag)">
                                                    {{tag}}
                                                </el-tag>
                                                <el-input class="input-new-tag" v-if="inputOptionVisible" v-model="optionValue" ref="saveOptionInput" size="small" @keyup.enter.native="handleOptionConfirm" @blur="handleOptionConfirm">
                                                </el-input>
                                                <el-button v-else class="button-new-tag" size="small" @click="showOptionInput">+ 新增选项</el-button>
                                            </div>
                                            <el-button type="text" @click="addField" :disabled="fieldType === '' || fieldTitle === ''" ${hasEditPermission('PROD_EXTRA')}><i class="el-icon-plus"></i>添加</el-button>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <#if hasPermission('PROD_MINIPROGRAM_URL')>
                                    <el-col :span="24">
                                        <el-form-item label="小程序链接">
                                            <label v-if="form.id">pages/productInfo/productInfo?productId={{ form.id }}</label>
                                            <label v-else style="color: #888;">请在保存之后查看</label>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <#if hasPermission('PROD_MINIPROGRAM_QRCODE')>
                                    <el-col>
                                        <el-form-item label="小程序二维码">
                                            <!-- <label v-if="form.id">http://qr.liantu.com/api.php?text={{ encodeURIComponent('https://release.zhen-yee.com/yq/api/productInfo?productId=' + form.id) }}</label> -->
                                            <img v-if="form.id" :src="'http://release.zhen-yee.com/api/qrcode?text=' + encodeURIComponent('https://release.zhen-yee.com/yq/api/productInfo?productId=' + form.id)" />
                                            <label v-else style="color: #888;">请在保存之后查看</label>
                                        </el-form-item>
                                    </el-col>
                                </#if>
                                <el-col>
                                    <el-form-item>
                                        <el-button type="primary" @click="onSubmit">保存</el-button>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <el-dialog title="添加/编辑规格" :visible.sync="sizeDialogVisible">
                            <el-form :model="sizeToAdd">
                                <el-form-item label="规格" label-width="80px">
                                    <el-input v-model="sizeToAdd.title"></el-input>
                                </el-form-item>
                                <el-form-item label="价格" label-width="80px">
                                    <el-input v-model="sizeToAdd.fee" type="number"></el-input>
                                </el-form-item>
                                <el-form-item label="库存" label-width="80px">
                                    <el-input v-model="sizeToAdd.storage" type="number"></el-input>
                                </el-form-item>
                                <el-form-item label="图片" label-width="80px">
                                    <el-upload class="avatar-uploader" :on-success="handleSizeImgSuccess" :on-error="handleSizeImgError" :http-request='uploadQnFile' list-type='picture' :show-file-list="false">
                                        <img v-if="sizeToAdd.image" :src="sizeToAdd.image" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                                <!-- <el-form-item label="排序" label-width="80px">
                                    <el-input v-model="sizeToAdd.sort" type="number"></el-input>
                                </el-form-item> -->
                                <el-form-item label="隐藏" label-width="80px">
                                    <el-checkbox v-model="sizeToAdd.isHidden" :false-label='0' :true-label='1' :checked='sizeToAdd.isHidden == 1' border>隐藏</el-checkbox>
                                </el-form-item>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="sizeDialogVisible = false">取 消</el-button>
                                <el-button type="primary" @click="submitSize">确 定</el-button>
                            </div>
                        </el-dialog>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/yq/admin/components/footer.html" />
    </div>
    <#include "/yq/admin/components/scripts.html" />
    <#include "/components/qiniu.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                dialogTableVisible: false,
                dialogFormVisible: false,
                imgDatas: [],
                fileList: [],
                dialogImageUrl: '',
                dialogVisible: false,
                images: [],
                imageUrl: null,
                form: {
                    isGroup: 0,
                    isNeedTrack: 0,
                    isCoupon: 0,
                    cover: '',
                    shareImage: ''
                },
                shops: toJson(`${shops!}`),
                shop: {
                    name: `${info.name!''}`,
                    subtitle: `${info.subtitle!''}`,
                    desc: `${info.desc!''}`,
                    cover: `${info.cover!''}`,
                    images: `${info.images!''}`,
                    count: `${info.count!''}`,
                    price: `${info.price!''}`,
                    id: `${info.id!''}`,
                    type: `${info.type!''}`,
                },
                dynamicTags: [],
                inputVisible: false,
                inputValue: '',
                // 自定义信息字段
                extraFields: [],
                fieldType: '',
                fieldTitle: '',
                fieldOptions: [],
                inputOptionVisible: false,
                optionValue: '',
                // 自定义信息字段 end
                categories: toJson(`${categories!}`),
                sizeDialogVisible: false,
                isEditSize: false,
                sizes: [],
                sizeToAdd: {
                    title: '',
                    fee: '',
                    image: '',
                    storage: 0,
                    isHidden: 0
                },
                gallery: []
            }
        },
        mounted: function() {
            if ('${data!}') {
                this.form = toJson(`${data}`);
            }
            if (this.form.images) {
                var images = this.form.images.split(';');
                images.pop();
                for (var i = 0; i < images.length; i++) {
                    var filename = images[i].substring(images[i].lastIndexOf('/') + 1, images[i].indexOf('?') > 0 ? images[i].indexOf('?') : images[i].length);
                    var image = {
                        name: filename,
                        url: images[i]
                    }
                    this.fileList.push(image);
                }
            }
            if (this.form.gallery) {
                var gallery = this.form.gallery.split(';');
                gallery.pop();
                for (var i = 0; i < gallery.length; i++) {
                    var filename = gallery[i].substring(gallery[i].lastIndexOf('/') + 1, gallery[i].indexOf('?') > 0 ? gallery[i].indexOf('?') : gallery[i].length);
                    var image = {
                        name: filename,
                        url: gallery[i]
                    }
                    this.gallery.push(image);
                }
            }
            if (this.form.intro) {
                // console.log(this.form.intro)
                // console.log(backBr(this.form.intro))
                // this.form.intro =  backBr(this.form.intro)
            }
            if (this.form.services) {
                var serviceList = this.form.services.split(";");
                serviceList.pop();
                this.dynamicTags = serviceList;
            }
            if (this.form.extraJson) {
                this.extraFields = JSON.parse(this.form.extraJson);
            }
            if (this.form.sizes) {
                // this.sizes = JSON.parse(this.form.sizes);
                this.sizes = this.form.sizes;
            }
        },
        methods: {
            onSubmit() {
                var imgs = '';
                // console.log(this.imgDatas)
                // for (var idx = 0; idx < this.imgDatas.length; idx++) {
                //     var item = this.imgDatas[idx];
                //     alert('sss')
                //     if (item.response != null) {
                //         var url = item.response.data.url;
                //         imgs = imgs + url + ';'
                //     } else {
                //         imgs = imgs + item.url + ';'
                //     }
                // }
                if (this.form.cardType == 1 && !this.form.cardUseLimit && this.form.cardUseLimit != 0) {
                    msg("请输入次卡的使用次数");
                    return;
                }
                if (this.form.cardType == 2 && !this.form.cardAvailableDay && this.form.cardAvailableDay != 0) {
                    msg("请输入日卡的有效天数")
                    return;
                }
                if (this.form.cardType == 3 && !this.form.cardExpire) {
                    msg("请选择过期卡的过期时间");
                    return;
                }
                if (this.form.isNeedMoreInfo == 4 && this.extraFields.length < 1) {
                    msg("自定义信息至少需要一个字段");
                    return;
                }
                var services = '';
                if (this.dynamicTags.length > 0) {
                    for (var i = 0; i < this.dynamicTags.length; i++) {
                        services += this.dynamicTags[i] + ";";
                    }
                }
                var sizes = '';
                if (this.sizes.length > 0) {
                    sizes = JSON.stringify(this.sizes);
                }
                var images = '';
                for (var i = 0; i < this.fileList.length; i++) {
                    images += this.fileList[i].url + ";";
                }
                var gallery = '';
                for (var i = 0; i < this.gallery.length; i++) {
                    gallery += this.gallery[i].url + ";";
                }
                var param = {
                    productId: this.form.id,
                    shopId: this.form.shopId,
                    title: this.form.title,
                    subtitle: this.form.subtitle,
                    cover: this.form.cover,
                    intro: this.form.intro,
                    price: this.form.price,
                    salePrice: this.form.salePrice,
                    isGroup: this.form.isGroup,
                    isCoupon: this.form.isCoupon,
                    isNeedTrack: this.form.isNeedTrack,
                    isHidden: this.form.isHidden,
                    isNew: this.form.isNew,
                    groupCount: this.form.groupCount,
                    groupHours: this.form.groupHours,
                    type: this.form.type,
                    sort: this.form.sort,
                    storage: this.form.storage,
                    url: this.form.url,
                    services: services,
                    isNeedMoreInfo: this.form.isNeedMoreInfo,
                    extraJson: this.extraFields.length > 0 ? JSON.stringify(this.extraFields) : '',
                    categoryId: this.form.categoryId,
                    isHot: this.form.isHot,
                    shareTitle: this.form.shareTitle,
                    shareImage: this.form.shareImage,
                    sizes: sizes,
                    images: images,
                    cardType: this.form.cardType,
                    cardUseLimit: this.form.cardType == 1 ? this.form.cardUseLimit : '',
                    cardAvailableDay: this.form.cardType == 2 ? this.form.cardAvailableDay : '',
                    cardExpire: this.form.cardType == 3 ? this.form.cardExpire : '',
                    gallery: gallery,
                    address: this.form.address,
                    latlng: this.form.latlng
                }
                // console.log(param)
                var url = ''
                var ref = '${referer!""}'
                var url = '/yq/admin/product/submit'
                axiosRequest(param, url, ref)
            },
            showSizeDialog(item) {
                this.sizeDialogVisible = true;
                if (item) {
                    this.sizeToAdd = item;
                    this.isEditSize = true;
                } else {
                    this.sizeToAdd = {
                        title: '',
                        fee: '',
                        image: '',
                        storage: 0,
                        isHidden: 0
                    };
                    this.isEditSize = false;
                }
            },
            submitSize() {
                if (!this.sizeToAdd.title) {
                    msg("请输入规格");
                    return;
                }
                if (!this.sizeToAdd.fee) {
                    msg("请输入价格");
                    return;
                }
                if (this.sizeToAdd.storage === '') {
                    msg("请输入库存");
                    return;
                }
                for (var i = 0; i < this.sizes.length; i++) {
                    if (this.sizes[i].title == this.sizeToAdd.title && !this.isEditSize) {
                        msg("规格不能重复");
                        return;
                    }
                }
                if (!this.isEditSize) {
                    this.sizes.push(this.sizeToAdd);
                }
                this.sizeDialogVisible = false;
            },
            delSize(item) {
                this.sizes.splice(this.sizes.indexOf(item), 1);
            },
            moveSizeUp(item) {
                var index = this.sizes.indexOf(item);
                if (index == 0) {
                    return;
                }
                var itemsToExchange = this.sizes.splice(index - 1, 2);
                this.sizes.splice(index - 1, 0, itemsToExchange[1], itemsToExchange[0]);
            },
            moveSizeDown(item) {
                var index = this.sizes.indexOf(item);
                if (index == this.sizes.length - 1) {
                    return;
                }
                var itemsToExchange = this.sizes.splice(index, 2);
                this.sizes.splice(index, 0, itemsToExchange[1], itemsToExchange[0]);
            },
            fileChanged(file, fileList) {
                console.log(file)
                console.log(fileList)
                console.log(this.fileList2)
                this.imgDatas = fileList
                // console.log(fileList2)
                // console.log(this.imgDatas)
            },
            ck() {
                console.log(this.imgDatas)
            },
            req(file) {
                onUploadSMImage(file)
            },
            handleAvatarSuccess(res, file) {
                console.log(res)
                console.log(file)
                this.form.cover = res.data.url
                console.log(this.form.cover);
                // this.form.cover = URL.createObjectURL(file.raw);
            },
            handleAvatarError(err, file, fileList) {
                console.log(err);
            },
            handleSizeImgSuccess(res, file) {
                console.log(res)
                console.log(file)
                this.sizeToAdd.image = res.data.url
                console.log(this.sizeToAdd.image);
                // this.form.cover = URL.createObjectURL(file.raw);
            },
            handleSizeImgError(err, file, fileList) {
                console.log(err);
            },
            successImg(response, file, fileList) {
                var image = {
                    name: file.name,
                    url: response.data.url
                }
                this.fileList.push(image);
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
                this.fileList = fileList;
            },
            handelGalleryImgSuccess(response, file, fileList) {
                var image = {
                    name: file.name,
                    url: response.data.url
                }
                this.gallery.push(image);
            },
            handleGalleryImgRemove(file, fileList) {
                console.log(file, fileList);
                this.gallery = fileList;
            },
            handlePreview(file) {
                console.log(file);
                var layerOption = {
                    "title": "查看大图", //相册标题
                    "id": 0, //相册id
                    "start": 0, //初始显示的图片序号，默认0
                    "data": [ //相册包含的图片，数组格式
                        {
                            "alt": file.name,
                            "pid": file.uid, //图片id
                            "src": file.url, //原图地址
                            "thumb": "" //缩略图地址
                        }
                    ]
                }
                layer.photos({
                    photos: layerOption,
                    anim: 6
                })
            },
            handleShareImgSuccess(res, file) {
                console.log(res)
                console.log(file)
                this.form.shareImage = res.data.url
                // this.form.cover = URL.createObjectURL(file.raw);
            },
            useCoverForShare() {
                this.form.shareImage = this.form.cover;
            },
            handleShareImgError(err, file, fileList) {
                console.log(err);
            },
            handleClose(tag) {
                this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
            },
            showInput() {
                this.inputVisible = true;
                this.$nextTick(_ => {
                    this.$refs.saveTagInput.$refs.input.focus();
                });
            },
            handleInputConfirm() {
                let inputValue = this.inputValue;
                if (inputValue) {
                    this.dynamicTags.push(inputValue);
                }
                this.inputVisible = false;
                this.inputValue = '';
            },
            addField() {
                var self = this;
                var options = '';
                if (self.fieldType === 0 || self.fieldType === 1) {
                    if (self.fieldOptions.length == 0) {
                        msg("请添加至少一个选项");
                        return;
                    }
                    for (var i = 0; i < self.fieldOptions.length; i++) {
                        options += self.fieldOptions[i] + ';';
                    }
                }
                var field = {
                    type: self.fieldType,
                    title: self.fieldTitle,
                    options: options
                }
                self.extraFields.push(field);
                self.fieldType = '';
                self.fieldTitle = '';
                self.fieldOptions = [];
            },
            delField(field) {
                this.extraFields.splice(this.extraFields.indexOf(field), 1);
            },
            handleOptionClose(tag) {
                this.fieldOptions.splice(this.fieldOptions.indexOf(tag), 1);
            },
            showOptionInput() {
                this.inputOptionVisible = true;
                this.$nextTick(_ => {
                    this.$refs.saveOptionInput.$refs.input.focus();
                });
            },
            handleOptionConfirm() {
                let inputValue = this.optionValue;
                if (inputValue) {
                    this.fieldOptions.push(inputValue);
                }
                this.inputOptionVisible = false;
                this.optionValue = '';
            }
        },
        filters: {
            fmt(date) {
                return date
            }
        }
    })
    </script>
    <script>
    window.addEventListener('message', function(event) {
        // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
        var loc = event.data;
        if (loc && loc.module == 'locationPicker') { //防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
            console.log('location', loc);
            // vue.location = loc;
            // vue.latlng = loc.latlng.lat + "," + loc.latlng.lng;
            vue.form.address = loc.poiaddress;
            vue.form.latlng = loc.latlng.lat + "," + loc.latlng.lng;
            console.log('latlng', loc.latlng);
            vue.dialogTableVisible = false;
        }
    }, false);
    </script>
</body>

</html>